package com.bawan.utils;

/**
 * Desc:  加密工具类
 * Author: zhengcongchun
 * CreateTime: 2014-03-17 11:03
 * LastModifyTime: 2014-03-17 11:03
 * FinalModifier: zhengcongchun
 * Version: 1.0
 */
public class EncryptUtil {
    public static final int passwordOne = 10;
    public static final int passwordTwo = 1;

    public EncryptUtil(){}

    /**
     * 加密
     * @param password
     * @return
     */
    public static String doEncrypt(String password) {
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < password.length(); i ++) {
            int tmpChar = password.charAt(i);
            tmpChar ^= 1;
            tmpChar ^= 0xa;
            sb.append(Integer.toHexString(tmpChar));
        }
        return sb.toString().toUpperCase();
    }

    /**
     * 解密
     * @param password
     * @return
     */
    public static String doDeEncrypt(String password) {
        String deStr = password.toLowerCase();
        StringBuffer deStrBuf = new StringBuffer();
        for(int i = 0; i < deStr.length(); i += 2) {
            String subStr = deStr.substring(i, i + 2);
            int tmpChar = Integer.parseInt(subStr, 16);
            tmpChar ^= 1;
            tmpChar ^= 0xa;
            deStrBuf.append((char)tmpChar);
        }

        return deStrBuf.toString();
    }
}
